#include <iostream>
#include <vector>
#include <queue>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
int T;
cin >> T;
while (T--)
{
int n, m;
long long res = 0, sum = 0,d;
cin >> n >> m >> d;
priority_queue<int, vector<int>, greater<int>> Q;
for (int i = 1; i <= n; ++i)
{
int ai;
cin >> ai;
if (ai + sum - d * i > res)
res = ai + sum - d * i;
if (ai > 0)
{
Q.push(ai);
sum += ai;
}
if (Q.size() == (size_t)m)
{
sum -= Q.top();
Q.pop();
}
}
cout << res << endl;
}
return 0;
}
1430C - Numbers on Whiteboard | 1697B - Promo |
208D - Prizes Prizes more Prizes | 659A - Round House |
1492C - Maximum width | 171B - Star |
1512B - Almost Rectangle | 831B - Keyboard Layouts |
814A - An abandoned sentiment from past | 268C - Beautiful Sets of Points |
1391C - Cyclic Permutations | 11A - Increasing Sequence |
1406A - Subset Mex | 1365F - Swaps Again |
50B - Choosing Symbol Pairs | 1719A - Chip Game |
454B - Little Pony and Sort by Shift | 1152A - Neko Finds Grapes |
1719B - Mathematical Circus | 1719C - Fighting Tournament |
1642A - Hard Way | 285C - Building Permutation |
1719E - Fibonacci Strings | 1696C - Fishingprince Plays With Array |
1085A - Right-Left Cipher | 1508B - Almost Sorted |
1690C - Restoring the Duration of Tasks | 1055A - Metro |
1036D - Vasya and Arrays | 1139C - Edgy Trees |